package com.captain.special.哈希表;

import java.util.HashMap;
import java.util.Map;

/**
 * Des:
 *
 * @author XL
 * @Date 2022/4/4 15:36
 */
public class 两数之和1 {

    public int[] twoSum(int[] nums, int target) {
        //
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int value = nums[i];
            int key = target - value;
            if (map.containsKey(key)) {
                return new int[]{map.get(key), i};
            } else {
                map.put(value, i);
            }
        }
        return null;
    }
}
